package models

import (
	"gorm.io/gorm"
	"time"
	"user_srv/basic/config"
)

type Reservation struct {
	Id                uint           `gorm:"column:id;type:bigint(20) UNSIGNED;primaryKey;not null;" json:"id"`
	UserId            uint           `gorm:"column:user_id;type:bigint(20);comment:用户Id;not null;" json:"user_id"`                                                                                      // 用户Id
	ServiceType       string         `gorm:"column:service_type;type:varchar(30);comment:服务类型;not null;" json:"service_type"`                                                                         // 服务类型
	HouseNum          uint           `gorm:"column:house_num;type:int(10);comment:房源面积;not null;" json:"house_num"`                                                                                   // 房源面积
	Address           string         `gorm:"column:address;type:varchar(30);comment:房源地址;not null;" json:"address"`                                                                                   // 房源地址
	JobTime           time.Time      `gorm:"column:job_time;type:datetime(3);comment:工作时长;not null;" json:"job_time"`                                                                                 // 工作时长
	CleanerId         uint           `gorm:"column:cleaner_id;type:bigint(20);comment:保洁Id;not null;" json:"cleaner_id"`                                                                                // 保洁Id
	EstimatePrice     float64        `gorm:"column:estimate_price;type:decimal(10, 2);comment:预估价格;not null;" json:"estimate_price"`                                                                  // 预估价格
	ReservationStatus uint           `gorm:"column:reservation_status;type:tinyint(1) UNSIGNED;comment:预约状态:1:等待保洁室接单，2:已接单，3:已完成，4:拒单;not null;default:1;" json:"reservation_status"` // 预约状态:1:等待保洁室接单，2:已接单，3:已完成，4:拒单
	CreatedAt         time.Time      `gorm:"column:created_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"created_at"`
	UpdatedAt         time.Time      `gorm:"column:updated_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"updated_at"`
	DeletedAt         gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);default:NULL;" json:"deleted_at"`
}

func (r *Reservation) TableName() string {
	return "reservation"
}
func (r *Reservation) AddReservation() error { //添加预约
	return config.DB.Create(&r).Error
}
func (r *Reservation) ReservationList() (ReservationLists []*Reservation, err error) {
	err = config.DB.Find(&ReservationLists).Error
	return
}
func (r *Reservation) GetReserVitionId(id int) error {
	return config.DB.Where("id = ?", id).Limit(1).Find(&r).Error
}
